package server.io.game.fact.room;

import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;

import server.io.game.fact.Fact_Scene;
import server.io.game.fact.game.Game_Base;
import server.io.game.fact.game.Game_Normal;
import server.io.game.fact.user.User_Base;
import server.io.game.fact.user.User_Normal;
import server.io.pro.bean.Pro_JoinHall;
import server.io.pro.bean.Pro_StartGame;
import server.io.pro.bean.Pro_JoinHall.Send;
import server.io.pro.bean.Pro_JoinRoom;
import server.io.pro.ctrl.Pro_Adapter_Base;

public abstract class Room_Base extends Fact_Scene implements Room_Inter
{
	// 房间顺序号
	public int room_number;
	// 用户昵称
	public String room_name;
	// 房间容纳最多人数
	public int room_size;
	// 房间密码
	public String room_password;
	// 房间类型 1v1 8人自由等等
	public String room_type;
	// 房间当前用户数
	public int user_amount;
	// 房间中的游戏
	public Game_Normal game = null;
	// 外观
	public String drawable_surface = null;

	public Room_Base()
	{
		// TODO Auto-generated constructor stub
		this.nat_sceneName = "room";
	}

	public Room_Base(int id, String fact_id, String fact_type)
	{
		super(id, fact_id, fact_type);
		this.nat_sceneName = "room";
	}

	@Override
	public void init()
	{
		// TODO Auto-generated method stub
		super.init();
	}

	public Game_Base startGame()
	{
		this.state = "playing";
		this.game = new Game_Normal(1, "1", 15, this.users);
		this.game.startGame();
		// this.game.allotHandCard();
		return this.game;
	}

	public int ChooseHero(int player_number, String hero_name)
	{
		return 0;
	}

	@Override
	public void control(int aStrId, String aStr, SelectionKey key)
	{
		// TODO Auto-generated method stub
		super.control(aStrId, aStr, key);

		byte[] _send = null;
		switch (aStrId)
		{
		// 进入游戏
		case 5051:
			System.out.println(" game !" + aStr);
			Pro_StartGame _startGame = new Pro_StartGame();
			_startGame._recv = Pro_Adapter_Base.jsonToObject(aStr,
					Pro_StartGame.Recv.class);
			Game_Base _game = this.startGame();
			_startGame._send = _startGame.new Send(_game);
			_send = nat_mProAdp_Send.encapProtocol(_startGame._send);
			break;
		default:
			break;
		}

		this.send(_send, "one", key);

	}

}
